package 接口.接口使用实例2;

import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 姚东名
 * Date: 2024-06-19
 * Time: 22:11
 */
class Student1 {
    public String name;
    public int age;
    public Student1(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student1{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
public class Test2 {
    public static void main(String[] args) {
        Student[] students = new Student[] {
                new Student("张三", 10),
                new Student("李四", 20),
                new Student("王五", 17),
        };

        System.out.println("排序前：" + Arrays.toString(students));
        //用年龄来比较：
        AgeComparator ageComparator = new AgeComparator();
        Arrays.sort(students, ageComparator);
        System.out.println("排序后：" + Arrays.toString(students));
    }
    public static void main1(String[] args) {
        Student[] students = new Student[] {
                new Student("张三", 10),
                new Student("王五", 17),
                new Student("李四", 20)
        };

        System.out.println("排序前：" + Arrays.toString(students));
        //用姓名来比较：
        NameComparator nameComparator = new NameComparator();
        Arrays.sort(students, nameComparator);
        System.out.println("排序后：" + Arrays.toString(students));
    }
}
